package com.samsung.list;

import java.util.Calendar;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.samsung.R;

public class ItemView extends LinearLayout
{
	
	private ImageView imageView;
	private TextView name;
	private TextView date;
	private ListItem item;

	public ListItem getItem()
	{
		return item;
	}

	public void setItem(ListItem item)
	{
		Calendar cal = Calendar.getInstance();
		Drawable drawable = null;
		this.item = item;
		cal.setTimeInMillis(item.getDate());
		date.setText(String.format("%d/%02d/%02d\n%02d:%02d",cal.get(Calendar.YEAR),cal.get(Calendar.MONTH)
				,cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE)));
		
		name.setText(item.getName());
		switch(item.getType())
		{
		case 1:
			drawable = getResources().getDrawable(R.drawable.call);
			break;
			
		case 2:
			drawable = getResources().getDrawable(R.drawable.message);
			break;
			
		case 3:
			drawable = getResources().getDrawable(R.drawable.picture);
		}
		
		imageView.setImageDrawable(drawable);
	}

	public ItemView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public ItemView(Context context)
	{
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onFinishInflate()
	{
		// TODO Auto-generated method stub
		super.onFinishInflate();
		
		imageView = (ImageView) findViewById(R.id.imageView);
		name = (TextView) findViewById(R.id.name);
		date = (TextView) findViewById(R.id.date);
	}

}